package com.his.server.main;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.his.server.consts.ServerConsts;
import com.his.server.utils.main.BaseContext;
import com.his.server.logicdata.BaseLogicData;
import com.his.server.logicdata.UserInfoLogicData;
import javax.servlet.http.HttpServletResponse;

public class MainResponseAction extends ActionSupport {
	 
    String methodname = null;
    String requestflag = null;
    
    @Override
    public String execute() throws Exception {
    	
            return super.execute();
    }
    
    public String responsePatch() {
    	
    	HttpServletResponse response = BaseContext.getServletResponse();
    	BaseLogicData baseLogicdata = (BaseLogicData) BaseContext.getAtribute(ServerConsts.SK_BASELOGICDATA);
    	UserInfoLogicData userInfoLogicData = (UserInfoLogicData) BaseContext.getAtribute(ServerConsts.SK_USERINFOLOGICDATA);
    	
    	if (baseLogicdata != null) {
        	requestflag = baseLogicdata.getRequestflag();
        	methodname = baseLogicdata.getMethodname();
    	}

    	if (!StringUtils.isEmpty(requestflag) && 
    			StringUtils.equals(requestflag, ServerConsts.REQUEST_SUCCESS)) {
    		
    		if (StringUtils.equals(methodname, ServerConsts.REQUEST_CONNECT)) {
    			//writeOut(response, ServerConsts.CONNECT_SUCCESS);
    		} else if (StringUtils.equals(methodname, ServerConsts.REQUEST_LOGIN)) {
    			
    			loginResponse(userInfoLogicData);   			
    		}
    	} else {
    		
    	}
    	
    	return ServerConsts.SUCCESS;
    }
    
	/**
	 * 
	 * @param jsonStr
	 */
    private void writeOut(HttpServletResponse response, Object jsonStr) {
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache, must-revalidate");
		response.setHeader("Pragma", "no-cache");
		try {

			response.getWriter().write((String)jsonStr);
			response.getWriter().flush();
			response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void loginResponse (UserInfoLogicData userInfoLogicData) {
		
		if (StringUtils.equals(userInfoLogicData.getLoginflag(), ServerConsts.LOGINFLAG_0)) {
			
		} else if (StringUtils.equals(userInfoLogicData.getLoginflag(), ServerConsts.LOGINFLAG_1)) {
			
		} else if (StringUtils.equals(userInfoLogicData.getLoginflag(), ServerConsts.LOGINFLAG_2)) {
			
		}
	}
}